<?php
class Plugin_Router extends Zend_Controller_Plugin_Abstract {

  public function routeStartup(Zend_Controller_Request_Abstract $request) {
    $uri = $_SERVER['REQUEST_URI'];
    if (!is_int(stripos($uri, '/ru')) && !is_int(stripos($uri, '/en'))&& !is_int(stripos($uri, '/fr'))) 
    {
        $Config = Zend_Registry::get('config');
        //$uri = substr($uri, strlen($Config->baseurl));
        $request->setRequestUri( "/" . Zend_Registry::get('Locale') . $uri);
    	$request->setParam('lang', Zend_Registry::get('Locale'));
    }
  }
  
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        Zend_Layout::startMvc(array(
                 'layoutPath' => APPLICATION_PATH . "/views/scripts/" . $request->getParam('lang',''),
                 'layout' => 'layout',
        ));
        $layout = Zend_Layout::getMvcInstance();
        $view = $layout->getView();
                
        $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
        $viewRenderer->setViewScriptPathSpec($request->getParam('lang','') . '/:controller/:action.:suffix');
        Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
        
        
        
    }
}